﻿// ==========================================================================
// Samples.cs
// Silverlight Shapes Library
// ==========================================================================
// Copyright (c) Silverlight Shapes Development Group
// All rights reserved.
// ==========================================================================

using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Windows.Controls;
using System.Windows.Navigation;

namespace SD.Samples.Views
{
    /// <summary>
    /// Interaction logic for Samples.xaml
    /// </summary>
    public partial class Samples : Page
    {
        #region Properties

        /// <summary>
        /// Gets or sets the view model that is injected by the managed extensibility framework.
        /// </summary>
        /// <value>
        /// The view model that is injected by the managed extensibility framework.
        /// </value>
        [Import]
        public SamplesViewModel ViewModel
        {
            get { return DataContext as SamplesViewModel; }
            set { DataContext = value; }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Samples"/> class.
        /// </summary>
        public Samples()
        {
            InitializeComponent();

            if (!DesignerProperties.IsInDesignTool)
            {
                CompositionInitializer.SatisfyImports(this);
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Called when a page becomes the active page in a frame.
        /// </summary>
        /// <param name="e">An object that contains the event data.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (ViewModel.LoadCommand.CanExecute(NavigationContext))
            {
                ViewModel.LoadCommand.Execute(NavigationContext);
            }
        }

        #endregion
    }
}
